package com.ymttest.database.sqlwapper;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.BillnoRule;
import com.ymttest.database.model.BillnoRuleExample;
import com.ymttest.database.model.BillnoRuleObservation;
import com.ymttest.database.model.BillnoRuleObservationExample;
import com.ymttest.database.model.BillnoRuleOffender;
import com.ymttest.database.model.BillnoRuleOffenderExample;

/************************************************************************************
 * @File name : YmtUserWapper.java
 * @Author : zhouyi
 * @Date : 2015年4月2日
 * @Copyright : 洋码头
 ************************************************************************************/
public class BillnoRuleWapper {
	SqlManager manage;

	public BillnoRuleWapper() {
		manage = new SqlManager("ymtlogistics");
	}

	/**
	 * billno_rule
	 * @return
	 * @throws InterruptedException
	 */
	public List<BillnoRule> selectBillnoRule(String expressCode, String regex)
			throws InterruptedException {

		BillnoRuleExample example = new BillnoRuleExample();

		BillnoRuleExample.Criteria criteria = example.createCriteria();

		if (expressCode != null) {

			if (expressCode.contains("%")) {

				criteria.andYmt_expresscodeLike(expressCode);

			} else {

				criteria.andYmt_expresscodeEqualTo(expressCode);

			}
		}

		if (regex != null) {

			criteria.andRegex_ruleEqualTo(regex);

		}

		List<BillnoRule> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.BillnoRuleMapper.selectByExample",
						example);

		if (CollectionUtils.isEmpty(result)) {

			return null;
		}

		return result;
	}

	/**
	 * billno_rule_offender
	 * @param bizNo
	 * @return
	 * @throws InterruptedException
	 */
	public List<BillnoRuleOffender> selectBilloffenderbyBizNo(String bizNo)
			throws InterruptedException {

		BillnoRuleOffenderExample example = new BillnoRuleOffenderExample();

		BillnoRuleOffenderExample.Criteria criteria = example.createCriteria();

		criteria.andBiz_noEqualTo(bizNo);

		List<BillnoRuleOffender> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.BillnoRuleOffenderMapper.selectByExample",
						example);
		if (CollectionUtils.isEmpty(result)) {

			return null;
		}

		return result;
	}

	/**
	 * billno_rule_observation
	 * @param bizNo
	 * @return
	 * @throws InterruptedException
	 */
	public List<BillnoRuleObservation> selectBillobservationbyBizNo(String bizNo)
			throws InterruptedException {

		BillnoRuleObservationExample example = new BillnoRuleObservationExample();

		BillnoRuleObservationExample.Criteria criteria = example
				.createCriteria();

		criteria.andBiz_noEqualTo(bizNo);

		List<BillnoRuleObservation> result = manage
				.getSelectResults(
						"com.ymttest.database.mapping.BillnoRuleObservationMapper.selectByExample",
						example);

		if (CollectionUtils.isEmpty(result)) {

			return null;
		}

		return result;
	}

	public static void main(String args[]) {
		try {

			Logger.debug(new BillnoRuleWapper().selectBilloffenderbyBizNo(
					"Au606651671").size());

		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
